<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: wu
// +----------------------------------------------------------------------

/**
 * 图像操作类库
 * @category   ORG
 * @package  ORG
 * @subpackage  Util
 * @author    wuxiansen
 */
class Image {
    static function buildImageVerify($x,$y) {
        //输出头像head头
        header("Content-type: image/png");
        //创建画布
        $im=imagecreatetruecolor($x, $y);
        //创建颜色
        $black = imagecolorallocate($im, 0, 0, 0);
        $white = imagecolorallocate($im, 255, 255, 255);
        //开始绘画
        for($i=0;$i<300;$i++){
            imagesetpixel($im,mt_rand(0, $x),mt_rand(0, $y),$white);
        }
        for($i=0;$i<5;$i++){
            imageline($im, mt_rand(0, $x), mt_rand(0, $y), mt_rand(0, $x), mt_rand(0, $y), $white);
        }
        $str=mt_rand(0, 9).mt_rand(0, 9).mt_rand(0, 9).mt_rand(0, 9);
        //将$str放入SESSION中
        $_SESSION['verify']=$str;
        imagestring($im, 5, ($x-48)/2, ($y-15)/2, $str, $white);
        //输出(格式)
        imagepng($im);
        //销毁
        imagedestroy($im);
    }
}